package algorithm.kmp;

public class violenceMatch {

  public static void main(String[] args) {
    System.out.println(violenceMatch("will", "il"));
  }

  public static int violenceMatch(String str1,String str2){

    int i = 0;
    int j = 0;
    char[] char1 = str1.toCharArray();
    char[] char2 = str2.toCharArray();

    while (i < char1.length && j < char2.length){
      if (char1[i] == char2[j]){
        i++;
        j++;
      }else {
        i = i - j + 1;
        j = 0;
      }
    }

    if (j == char2.length){
      return i - j;
    }else {
      return -1;
    }

  }
}
